package com.jianda.view.windows;

import com.jianda.service.WaveDataService;
import com.jianda.view.MenuView;
import com.jianda.view.TextView;

import javax.swing.*;
import java.awt.*;

/**
 * 主要窗口
 */
public class Mainwindows extends JFrame {

    private static Mainwindows mainwindows;

    public static Mainwindows getInstance() {
        if (mainwindows == null) {
            synchronized (Mainwindows.class) {
                if (mainwindows == null) {
                    mainwindows = new Mainwindows();
                }
            }
        }
        return mainwindows;
    }

    public Mainwindows() {
        // 设置标题
        setTitle("串口波形图展示");

        // 添加菜单栏
        MenuView.editMenu(this);

        // 窗口关闭则退出应用程序
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 添加标签
        TextView.editText(this);

        // 添加波形
        JPanel jPanel = new JPanel();
        jPanel.setBackground(Color.LIGHT_GRAY);
        jPanel.add(WaveDataService.getInstance(this));
        getContentPane().add(jPanel);

        // 设置自由布局
        setUndecorated(false);

        // 设置全屏显示
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle bounds = new Rectangle(screenSize);
        setBounds(bounds);
        setExtendedState(JFrame.MAXIMIZED_BOTH);

        // 使界面可视
        setVisible(true);

        System.out.println("Main-X:" +  getBounds().getX());
        System.out.println("Main-Y:" +  getBounds().getY());
        System.out.println("Main-W:" +  getBounds().width);
        System.out.println("Main-H:" +  getBounds().height);
    }
}
